package com.yvpi.yvpicturebackend.api.imagesearch;

import com.yvpi.yvpicturebackend.api.imagesearch.model.ImageSearchResult;
import com.yvpi.yvpicturebackend.api.imagesearch.sub.GetImageFirstUrlApi;
import com.yvpi.yvpicturebackend.api.imagesearch.sub.GetImageListApi;
import com.yvpi.yvpicturebackend.api.imagesearch.sub.GetImagePageUrlApi;
import lombok.extern.slf4j.Slf4j;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

/**
 * 门面模式，将多个Api调用组合到一起，方便客户端调用
 */
@Slf4j
public class ImageSearchApiFacade {
    public static List<ImageSearchResult> searchImage(String imageUrl) {
        String imagePageUrl = GetImagePageUrlApi.getImagePageUrl(imageUrl);
        String imageFirstUrl = GetImageFirstUrlApi.getImageFirstUrl(imagePageUrl);
        List<ImageSearchResult> imageList = GetImageListApi.getImageList(imageFirstUrl);
        return imageList;

    }
        public static void main(String[] args) {
            // 测试以图搜图功能
            String imageUrl = "https://www.codefather.cn/logo.png";
            List<ImageSearchResult> resultList = searchImage(imageUrl);
            System.out.println("结果列表" + resultList);
        }
}
